
function WebEntityComboList(id, type) {
    this.superClase = WebComboList;
    this.superClase(id, type);

    this.entityName = "";
    this.orderBy = "";
    this.foreingProperty = "";
    this.initValue = "";
    this.propertyId = "";
    this.propertyDescription = "";

    this.loadingString = "Loading...";

    this.Clone = EntityComboList_Clone;

    this.Fill = EntityComboList_Fill;
    this.BeginLoading = EntityComboList_BeginLoading;
    this.EndLoading = EntityComboList_EndLoading;
    this.evalOnChange = EntityComboList_EvalOnChange;
    this.RefreshData = EntityComboList_RefreshData;
    this.RefreshDataSinc = EntityComboList_RefreshDataSinc;
}

function EntityComboList_Clone(newId) {
    var newCombo = new WebEntityComboList(newId, this.type);

    newCombo.width = this.width;
    newCombo.size = this.size;
    newCombo.labelclear = this.labelclear;
    newCombo.multiselect = this.multiselect;
    newCombo.redraw = this.redraw;
    newCombo.cssClass = this.cssClass;

    newCombo.items = this.items.slice();
    newCombo.count = this.count;
    newCombo.resizable = this.resizable;
    newCombo.scroll = this.scroll;
    newCombo.enabled = this.enabled;

    newCombo.entityName = this.entityName;
    newCombo.orderBy = this.orderBy;
    newCombo.foreingProperty = this.foreingProperty;

    return newCombo;
}

function EntityComboList_EvalOnChange() {
    if (typeof (Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.GetValueList());

    eval(this.onChange);
}

function EntityComboList_Fill(items) {
    if (!Common.isArray(items))
        return -1;

    this.redraw = false;
    this.ClearList();

    // item para deseleccionar (solo para combos)
    if (this.type != 1)
        this.AddItem('', '');

    var keyvalue;
    for (var i = 0; i < items.length; i++) {
        keyvalue = items[i].split("|");
        this.AddItem(keyvalue[0], keyvalue[1]);
    }

    this.redraw = true;
    this.Refresh();
}

function EntityComboList_BeginLoading() {
    this.Disable();
}

function EntityComboList_EndLoading() {
    this.Enable();
}

function EntityComboList_RefreshData(parentValue) {
    var property = this.foreingProperty;
    var orderBy = this.orderBy;
    var propertyId = this.propertyId;
    var propertyDesc = this.propertyDescription;

    if (!parentValue)
        parentValue = "";

    // llamado Ajax para refrescar la lista 
    this.BeginLoading();
    EntityComboList.GetList(this.id, this.entityName, property, parentValue, orderBy, propertyId, propertyDesc, EntityComboList_GetListCallBack, this.id);
}

function EntityComboList_RefreshDataSinc(parentValue) {
    var property = this.foreingProperty;
    var orderBy = this.orderBy;
    var propertyId = this.propertyId;
    var propertyDesc = this.propertyDescription;

    if (!parentValue)
        parentValue = "";

    // llamado Ajax para refrescar la lista 
    this.BeginLoading();

    var response = EntityComboList.GetList(this.id, this.entityName, property, parentValue, orderBy, propertyId, propertyDesc);
    response.context = this.id;
    EntityComboList_GetListCallBack(response);
}

function EntityComboList_RegisterRelationship(idparent, idchild) {
    Entity_Relationships[idparent] = idchild;
}

function EntityComboList_GetListCallBack(response) {
    var listId = response.context;
    var mlist = ComboList_Instances[listId];

    if (response.error) {
        alert(response.error);
    }
    else {
        var items = response.value;
        if (items)
            mlist.Fill(items);

        mlist.evalOnChange();
    }

    mlist.EndLoading();
}    
